﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace RemoteTestRunner.FormsUI.Wpf.Converters
{
    public class BooleanConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string parameters = parameter as string;
            if (parameters == null)
            {
                throw new ArgumentNullException("parameter", "Converter parameters must be specified.");
            }

            string[] parameterArray = parameters.Split(',');

            bool boolValue = (bool)value;

            if (boolValue || parameterArray.Length == 1)
            {
                return parameterArray[0];
            }
            else
            {
                return parameterArray[1];
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }

        #endregion
    }
}